<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>查货信息页面</title>
    <jsp:include page="../../head.jsp"/>
</head>
<script type="text/javascript">
    <%String checking_id = request.getParameter("checkingGoods.checking_id");%>
    var formSetting = {
        title: "查货基础数据",
        module: 'save',
        columns: [{
            name: "checking_id",
            label: "CHECKING_ID",
            hidden: true
        },
            {
                name: "companyQp.company_code",
                label: "经营单位",
                url: "companyqp-findCompanyByCode?tdateaa=" + timeNum(),
                dropdownType: "ajax",
                type: "dropdown",
                minLength: 0
            },
            {
                name: "route",
                type: "dropdown",
                data: [["转关", "T"], ["直航", "D"]],
                minLength: 0,
                label: "转关/直航"
            }, {
                name: "declaration_no",
                label: "报关单号"
            }, {
                name: "container_info",
                label: "柜数/尺码"
            }, {
                name: "container_no",
                label: "柜号",
                dropdownType: "ajax",
                type: "dropdown",
                minLength: 0
                <%
                if(StringUtils.isNotEmpty(checking_id)){
                    out.print(",");
                    out.println("url:'checkingGoods-initContainerNoByDeclarationNo?checking_id="+checking_id+"',");
                }
                %>
            }, {
                name: "heap_position",
                label: "堆位"
            }, {
                name: "camera_position",
                label: "摄像头位"
            }, {
                name: "check_official",
                label: "查验关员"
            }, {
                name: "seal_no",
                label: "封条号码"
            }, {
                name: "commodity.id",
                label: "货物名称",
                dropdownType: "ajax",
                type: "dropdown",
                minLength: 0
                <%
                if(StringUtils.isNotEmpty(checking_id)){
                    out.print(",");
                    out.println("url:'checkingGoods-initCommoditiesByDeclarationNo?checking_id="+checking_id+"',");
                }
                %>
            }, {
                name: "specifications",
                label: "规格/包装"
            }, {
                name: "check_items",
                label: "查验项目"
            }, {
                name: "declaration_weight",
                label: "报关重量"
            }, {
                name: "receipt_check_notice",
                label: "签收查验通知书"
            }, {
                name: "status",
                type: "dropdown",
                data: [["已查验", "1"], ["未查验", "0"]],
                minLength: 0,
                label: "完成情况"
            }],
        form: {
            'url': 'checkingGoods-saveOrUpdate',
            'data': function () {
                var id = "${checking_id}";
                if (id) {
                    var dataValue = "";
                    $.ajax({
                               url: "checkingGoods-find?checking_id=" + id,
                               async: false,
                               cache: false,
                               success: function (data) {
                                   dataValue = data;
                               }
                           });

                    if (dataValue.companyQp != null) {
                        var dropdownName = $.mrdForm.getDropDwonLabelName(
                                "companyQp.companyCode");
                        dataValue[dropdownName] = dataValue.companyQp.COMPANY_NAME;
                    }
                    if (dataValue.commodity != null) {
                        var dropdownName = $.mrdForm.getDropDwonLabelName(
                                "commodity.id");
                        dataValue[dropdownName] = dataValue.commodity.name;
                    }
                    if (dataValue.container_no != null) {
                        var dropdownName = $.mrdForm.getDropDwonLabelName(
                                "container_no");
                        dataValue[dropdownName] = dataValue.container_no;
                    }
                    return dataValue;
                } else {
                    return null;
                }
            },
            'afterAjaxSuccess': function (responseText, statusText, xhr, $form) {
            }
        },
        buttons: {
            custom: [
                {
                    id: "cancelbtn",
                    value: "返回",
                    click: function () {
                        history.go(-1);
                    }
                }
            ]
        }
    };
    $(document).ready(function () {
        $("#formtable").mrdForm(formSetting);

        $("input[name='declaration_no']").keydown(function (e) {
            if (e.keyCode == 13) {
                var declaration_no = $(this).val();

                $.ajax({
                           url: "checkingGoods-initCompanyByDeclarationNo?declaration_no="
                                + declaration_no,
                           async: false,
                           cache: false,
                           success: function (data) {
                               $("input[name='companyQp.companyCode']").val(
                                       data.companyQp.companyCode);
                               $("input[name='control_checkingGoods_companyQp_companyCode_dropdown']").val(
                                       data.companyQp.COMPANY_NAME);
                           }
                       });

                $.ajax({
                           url: "checkingGoods-initCommoditiesByDeclarationNo?declaration_no="
                                + declaration_no,
                           async: false,
                           cache: false,
                           success: function (data) {
                               $("input[name='control_checkingGoods_commodity_id_dropdown']").autocomplete(
                                       {
                                           source: data.results
                                       });
                           }
                       });

                $.ajax({
                           url: "checkingGoods-initContainerNoByDeclarationNo?declaration_no="
                                + declaration_no,
                           async: false,
                           cache: false,
                           success: function (data) {
                               $("input[name='control_container_no_dropdown']").autocomplete(
                                       {
                                           source: data.results
                                       });
                           }
                       });
            }
        });
    });
</script>
<body>
<div style="width: 100%">
    <div id="formtable"></div>
</div>
</body>
</html>
